/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jp.co.irep.juten.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author toan_nguyen
 */
@Entity
@Table(name = "place")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Place.findAll", query = "SELECT p FROM Place p"),
    @NamedQuery(name = "Place.findById", query = "SELECT p FROM Place p WHERE p.id = :id"),
    @NamedQuery(name = "Place.findByName", query = "SELECT p FROM Place p WHERE p.name = :name"),
    @NamedQuery(name = "Place.findByMemo", query = "SELECT p FROM Place p WHERE p.memo = :memo"),
    @NamedQuery(name = "Place.findByDeleteFlg", query = "SELECT p FROM Place p WHERE p.deleteFlg = :deleteFlg"),
    @NamedQuery(name = "Place.findByDate", query = "SELECT p FROM Place p WHERE p.date = :date"),
    @NamedQuery(name = "Place.findByUpdate", query = "SELECT p FROM Place p WHERE p.update = :update"),
    //@NamedQuery(name = "Place.findByPrefectureId", query = "SELECT p FROM Place p WHERE p.prefecture.id = :prefectureId")
})
public class Place implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Size(max = 2147483647)
    @Column(name = "name")
    private String name;
    @Size(max = 2147483647)
    @Column(name = "memo")
    private String memo;
    @Basic(optional = false)
    @NotNull
    @Column(name = "delete_flg")
    private int deleteFlg;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Column(name = "update")
    @Temporal(TemporalType.TIMESTAMP)
    private Date update;
    @Basic(optional = false)
    @NotNull
    @Column(name = "prefecture_id")
    private int prefectureId;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "prefecture_id",referencedColumnName = "id",updatable = false, insertable = false)
    private Aken prefecture;
    
    
    public Place() {
    }

    public Place(Integer id) {
        this.id = id;
    }

    public Place(Integer id, int deleteFlg, Date date) {
        this.id = id;
        this.deleteFlg = deleteFlg;
        this.date = date;
        //this.prefecture = prefecture;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public int getDeleteFlg() {
        return deleteFlg;
    }

    public void setDeleteFlg(int deleteFlg) {
        this.deleteFlg = deleteFlg;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Date getUpdate() {
        return update;
    }

    public void setUpdate(Date update) {
        this.update = update;
    }

    public int getPrefectureId() {
        return prefectureId;
    }

    public void setPrefectureId(int prefectureId) {
        this.prefectureId = prefectureId;
    }
    public Aken getPrefecture() {
        return prefecture;
    }

    public void setPrefecture(Aken prefecture) {
        this.prefecture = prefecture;
    }
//    public Aken getAken() {
//        return aken;
//    }
//
//    public void setAken(Aken aken) {
//        this.aken = aken;
//    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Place)) {
            return false;
        }
        Place other = (Place) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jp.co.irep.tech.juten.jpa.entity.Place[ id=" + id + " ]";
    }
    
}
